﻿using System;
using System.Collections.Generic;
using System.Text;
using SerializationHelperLib;

namespace ConfigMgmtEx
{
    public class ConfManager : XmlPersistenceBase<ConfManager>
    {
        ConfigHash userCfg = new ConfigHash();

        public ConfigHash UserCfg
        {
            get { return userCfg; }
            set { userCfg = value; }
        }

        ConfigHash appCfg = new ConfigHash();

        public ConfigHash AppCfg
        {
            get { return appCfg; }
            set { appCfg = value; }
        }

        ConfigHash defaultCfg = new ConfigHash();

        public ConfigHash DefaultCfg
        {
            get { return defaultCfg; }
            set { defaultCfg = value; }
        }

        public ConfigEntry GetConfigEntry(string cfgId)
        {
            if (userCfg.ContainsKey(cfgId))
                return userCfg[cfgId];

            if (appCfg.ContainsKey(cfgId))
                return appCfg[cfgId];

            if (defaultCfg.ContainsKey(cfgId))
                return defaultCfg[cfgId];

            throw new Exception("GetConfigEntry: Unknown cfgId '" + cfgId + "'");
        }

        public void PersistChanges()
        {
            //throw new NotImplementedException();
        }
    }
}
